<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{   /*
    //显示post主页面
    */
    public function index(){
         if(\Auth::check()){
             return redirect('/posts');

         }
    	return view('login/index');

    }
    /*
    //登陆验证功能
    */
    public function pan(){
        //validate
        $this->validate(request(),[

                'email'=>'required|email',
                'password'=>'required|min:3',
                'is_remember'=>'integer'

        ]);
        //logic
        $user=request(['email','password']);
        $remember=boolval(request('is_remember'));

         if (\Auth::attempt($user,$remember)) {
            // 认证通过...
            return redirect('/posts');
        }
    	//登陆失败 返回登陆页面
        return back()->withErrors('email and password are eroors');
    }
    /*
        登出功能
    */
    public function logout(){
        \Auth::logout();
        return redirect('/login');
    	
    }
}
